/**
 * ...
 * @author Thot
 */

function MapProxy()
{
	this.init( MapProxy.NAME, new Array() );
}

POO.extend( MapProxy, Proxy );


	// static
	
	MapProxy.NAME = "MapProxy";
	
	//public
	
	MapProxy.prototype.init = function( p_name, p_data )
	{
		this._super.init.apply( this, [ p_name, p_data ] );
		this.listenNotifications();
	};
	
	MapProxy.prototype.listenNotifications = function()
	{
		this.addNotificationListener( ApplicationNotification.LOAD_PROJECT_COMPLETE, this.onNotification );
	};

	MapProxy.prototype.onNotification = function( p_notificationType, p_data )
	{
		switch ( p_notificationType )
		{
			case ApplicationNotification.LOAD_PROJECT_COMPLETE:	
				this._parseMapData(); 
				break;
		}
	};
	
	MapProxy.prototype.getMapVOById = function( p_id )
	{
		var vo = null;
		var i = 0;
		var max = this._data.length;
		
		for( ; i < max; i++ )
		{
			vo = this._data[i];
			if( vo.name == p_id )
				return vo;
		}
		
		return null;
	};
	
	MapProxy.prototype.removeMapVOById = function( p_id )
	{
		var vo = this.getMapVOById(p_id);
		var index = -1;
		if( vo != null )
		{
			index = this._data.indexOf(vo);
			this._data.splice( index, 1 );
		}
	};
	
	MapProxy.prototype.addMapVO = function( p_vo )
	{
		this._data.push( p_vo );
	};

	
	// private
	MapProxy.prototype._parseMapData = function()
	{
		var proxy = this.getFacade().getProxy( ApplicationProxy.NAME );
		var data = proxy.getMapsList();
		var i = 0;
		var j = 0;
		var max = data.length;
		var ma2 = data.length;
		var vo = null;
		var layerVO = null;
		var obj = null;
		var obj2 = null;
		
		for( ; i < max; i++ )
		{
			obj = data[i];
			vo = new MapVO();
			
			vo.layers = new Array();
			max2 = obj.layers.length;
			
			for( j = 0; j < max2; j++ )
			{
				obj2 = obj.layers[j];
				layerVO = new LayerVO();
				layerVO.name = obj2.name;
				layerVO.lazy = obj2.lazy;
				layerVO.sortFunc = obj2.sortFunc;
				layerVO.sortArgs = obj2.sortArgs;
				layerVO.displayList = obj2.displayList;
				
				vo.layers.push( layerVO );
			}
			
			vo.name = obj.name;
			vo.type = obj.type;
			this._data.push( vo );
		}
		
	};
	

	